package com.ruoyi.logistic.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.logistic.domain.*;
import com.ruoyi.logistic.domain.vo.NetworkEntryFeeSettleCollectVo;
import com.ruoyi.logistic.domain.vo.NetworkEntryFeeSettleVo;
import com.ruoyi.logistic.service.NetworkEntryFeeSettleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.util.List;

@RequestMapping("/network/entryFee")
@RestController
@Api(tags = "网点财务_进港派费结算")
public class NetworkEntryFeeSettleController {
    @Autowired
    private NetworkEntryFeeSettleService networkEntryFeeSettleService;

    @ApiOperation("显示进港结算明细列表")
    @GetMapping("/selectAll")
    public R selectAll(PageDate pageDate){
        List<NetworkEntryFeeSettle> networkEntryFeeSettleList = networkEntryFeeSettleService.selectAll(pageDate);
        if (networkEntryFeeSettleList == null || networkEntryFeeSettleList.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(PageInfo.info(networkEntryFeeSettleList));
        }
    }
    @ApiOperation("添加进港结算")
    @PostMapping("/insert")
    public R insert(@RequestBody NetworkEntryFeeSettle networkEntryFeeSettle){
        Boolean isAdd = networkEntryFeeSettleService.insert(networkEntryFeeSettle);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }
    @ApiOperation("修改进港结算")
    @PostMapping("/update")
    public R update(@RequestBody NetworkEntryFeeSettle networkEntryFeeSettle){
        Boolean isUpdate = networkEntryFeeSettleService.update(networkEntryFeeSettle);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }
    @ApiOperation("删除进港结算")
    @PostMapping("/deleteById")
    public R deleteById(Integer id){
        Boolean isDelete = networkEntryFeeSettleService.deleteById(id);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }
    @ApiOperation("搜索进港结算明细")
    @PostMapping("/search")
    public R search(@RequestBody NetworkEntryFeeSettleVo vo){
        if (vo.getStartTime() == null || vo.getEndTime() == null || vo.getNetworkNameId() == null){
            return R.fail("请输入查询所需要的时间信息和网点信息！");
        }
        List<NetworkEntryFeeSettle> networkEntryFeeSettleList = networkEntryFeeSettleService.search(vo);
        if (networkEntryFeeSettleList == null || networkEntryFeeSettleList.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(PageInfo.info(networkEntryFeeSettleList));
        }
    }

    @ApiOperation("汇总进港结算明细")
    @PostMapping("/collect")
    public R collect(@RequestBody NetworkEntryFeeSettleCollectVo vo){
        if (vo.getStartTime() == null || vo.getEndTime() == null || vo.getNetworkNameId() == null){
            return R.fail("请输入查询所需要的时间信息和网点信息！");
        }
        if (vo.getTimeType() == null || vo.getCollectType() == null){
            return R.fail("请选择汇总类型和时间类型！");
        }
        List<NetworkEntryFeeSettleCollect> collects = networkEntryFeeSettleService.collect(vo);
        if (collects == null || collects.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(PageInfo.info(collects));
        }
    }
}
